package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.example.myapplication.stepFragment.StepReadFragment1;
import com.example.myapplication.stepFragment.StepReadFragment2;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class StepReadActivity extends AppCompatActivity {

    int allstep = 14;
    int countpage = 0;
    ImageView pre;
    ImageView next;
    Fragment step[]=new Fragment[allstep];


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (getSupportActionBar() != null){
            getSupportActionBar().setTitle("步骤阅读");
        }

        setContentView(R.layout.activity_step_read);

        pre=findViewById(R.id.btn_pre_step);
        next=findViewById(R.id.btn_next_step);

        step[0]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_1);
        step[1]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_2);
        step[2]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_3);
        step[3]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_4);
        step[4]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_5);
        step[5]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_6);
        step[6]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_7);
        step[7]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_8);
        step[8]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_9);
        step[9]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_10);
        step[10]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_11);
        step[11]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_12);
        step[12]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_13);
        step[13]=getSupportFragmentManager().findFragmentById(R.id.fragment_step_14);


        hideAll();
        showStep(countpage);

        pre.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countpage-=1;
                countpage= Math.max(countpage, 0);
                hideAll();
                showStep(countpage);
            }
        });

        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                countpage+=1;
                countpage= Math.min(countpage, allstep-1);
                hideAll();
                showStep(countpage);
            }
        });
    }


    void showStep(int i)
    {
        getSupportFragmentManager().beginTransaction().show(step[i]).commit();
    }

    void hideAll()
    {
        for(int j=0;j<allstep;j++)
        {
            getSupportFragmentManager().beginTransaction().hide(step[j]).commit();
        }
    }
}